﻿/// <summary>
/// FileName: Variable.cs
/// Author: Jiang Xiaolong
/// Created Time: 2015.05.05
/// Version: 1.0
/// Company: Sunnytech
/// Function: 变量类；
///
/// Changed By:
/// Modification Time:
/// Discription:
/// </summary>
using System;

namespace Expression.impl
{
	public class Variable
	{
		public Type ExpType { get; set; }
		private object _value = null;
		private string _name = "";
		private bool _constant = false;

		public Variable(string name, Type type)
		{
			this._name = name;
			this.ExpType = type;
		}

		public Variable(string name, Type type, object value)
		{
			this._name = name;
			this.ExpType = type;
			this._value = value;
		}

		/// <summary>
		/// 设置变量值；
		/// </summary>
		/// <param name="value">变量值；</param>
		public void SetValue(object value)
		{
			if (!_constant)
			{
				this._value = value;
			}
		}

		/// <summary>
		/// 设置当前为常量；
		/// </summary>
		/// <param name="value">常量值；</param>
		public void MakeConstant(object value)
		{
			SetValue(value);
			this._constant = true;
		}

		/// <summary>
		/// 获得当前值；
		/// </summary>
		/// <returns>当前值；</returns>
		public object GetValue()
		{
			return _value;
		}

		public override string ToString()
		{
			return "Type: " + ExpType.ToString() + "---" + _name + ": " + _value.ToString();
		}

		/// <summary>
		/// 获取变量名；
		/// </summary>
		/// <returns>当前变量名；</returns>
		public string GetName()
		{
			return _name;
		}

		/// <summary>
		/// 是否为常量；
		/// </summary>
		/// <returns>是否为常量；</returns>
		public bool IsConstant()
		{
			return _constant;
		}
	}
}
